package com.youyi.yyviewsdklibrary.Dialog.core;

import android.app.Activity;
import android.arch.lifecycle.Lifecycle;
import android.arch.lifecycle.LifecycleObserver;
import android.arch.lifecycle.LifecycleOwner;
import android.arch.lifecycle.LifecycleRegistry;
import android.arch.lifecycle.OnLifecycleEvent;
import android.content.Context;
import android.os.Build;
import android.os.Handler;
import android.os.Looper;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewConfiguration;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.EditText;
import android.widget.FrameLayout;
import com.youyi.yyviewsdklibrary.Dialog.XPopup;
import com.youyi.yyviewsdklibrary.Dialog.animator.BlurAnimator;
import com.youyi.yyviewsdklibrary.Dialog.animator.EmptyAnimator;
import com.youyi.yyviewsdklibrary.Dialog.animator.PopupAnimator;
import com.youyi.yyviewsdklibrary.Dialog.animator.ScaleAlphaAnimator;
import com.youyi.yyviewsdklibrary.Dialog.animator.ScrollScaleAnimator;
import com.youyi.yyviewsdklibrary.Dialog.animator.ShadowBgAnimator;
import com.youyi.yyviewsdklibrary.Dialog.animator.TranslateAlphaAnimator;
import com.youyi.yyviewsdklibrary.Dialog.animator.TranslateAnimator;
import com.youyi.yyviewsdklibrary.Dialog.enums.PopupAnimation;
import com.youyi.yyviewsdklibrary.Dialog.enums.PopupStatus;
import com.youyi.yyviewsdklibrary.Dialog.impl.FullScreenPopupView;
import com.youyi.yyviewsdklibrary.Dialog.impl.PartShadowPopupView;
import com.youyi.yyviewsdklibrary.Dialog.util.KeyboardUtils;
import com.youyi.yyviewsdklibrary.Dialog.util.XPopupUtils;
import java.util.ArrayList;
import java.util.List;

public abstract class BasePopupView extends FrameLayout implements LifecycleObserver, LifecycleOwner {
    private final Runnable attachTask = new Runnable() {
        /* class com.youyi.yyviewsdklibrary.Dialog.core.BasePopupView.AnonymousClass1 */

        public void run() {
            BasePopupView.this.attachToHost();
            KeyboardUtils.registerSoftInputChangedListener(BasePopupView.this.getHostWindow(), BasePopupView.this, new KeyboardUtils.OnSoftInputChangedListener() {
                /* class com.youyi.yyviewsdklibrary.Dialog.core.BasePopupView.AnonymousClass1.AnonymousClass1 */

                @Override // com.youyi.yyviewsdklibrary.Dialog.util.KeyboardUtils.OnSoftInputChangedListener
                public void onSoftInputChanged(int i) {
                    BasePopupView.this.onKeyboardHeightChange(i);
                    if (!(BasePopupView.this.popupInfo == null || BasePopupView.this.popupInfo.xPopupCallback == null)) {
                        BasePopupView.this.popupInfo.xPopupCallback.onKeyBoardStateChanged(BasePopupView.this, i);
                    }
                    if (i == 0) {
                        XPopupUtils.moveDown(BasePopupView.this);
                        BasePopupView.this.hasMoveUp = false;
                    } else if (!(BasePopupView.this instanceof PartShadowPopupView) || BasePopupView.this.popupStatus != PopupStatus.Showing) {
                        XPopupUtils.moveUpToKeyboard(i, BasePopupView.this);
                        BasePopupView.this.hasMoveUp = true;
                    }
                }
            });
            BasePopupView.this.init();
        }
    };
    protected BlurAnimator blurAnimator;
    public FullScreenDialog dialog;
    Runnable dismissWithRunnable;
    protected Runnable doAfterDismissTask = new Runnable() {
        /* class com.youyi.yyviewsdklibrary.Dialog.core.BasePopupView.AnonymousClass6 */

        public void run() {
            View findViewById;
            BasePopupView.this.popupStatus = PopupStatus.Dismiss;
            BasePopupView.this.lifecycleRegistry.handleLifecycleEvent(Lifecycle.Event.ON_STOP);
            if (BasePopupView.this.popupInfo != null) {
                if (BasePopupView.this.popupInfo.autoOpenSoftInput.booleanValue()) {
                    BasePopupView basePopupView = BasePopupView.this;
                    if (basePopupView instanceof PartShadowPopupView) {
                        KeyboardUtils.hideSoftInput(basePopupView);
                    }
                }
                BasePopupView.this.onDismiss();
                XPopup.longClickPoint = null;
                if (BasePopupView.this.popupInfo.xPopupCallback != null) {
                    BasePopupView.this.popupInfo.xPopupCallback.onDismiss(BasePopupView.this);
                }
                if (BasePopupView.this.dismissWithRunnable != null) {
                    BasePopupView.this.dismissWithRunnable.run();
                    BasePopupView.this.dismissWithRunnable = null;
                }
                if (BasePopupView.this.popupInfo.isRequestFocus && BasePopupView.this.popupInfo.isViewMode && BasePopupView.this.getWindowDecorView() != null && (findViewById = BasePopupView.this.getWindowDecorView().findViewById(16908290)) != null) {
                    findViewById.setFocusable(true);
                    findViewById.setFocusableInTouchMode(true);
                }
                BasePopupView.this.detachFromHost();
            }
        }
    };
    protected Runnable doAfterShowTask = new Runnable() {
        /* class com.youyi.yyviewsdklibrary.Dialog.core.BasePopupView.AnonymousClass3 */

        public void run() {
            BasePopupView.this.popupStatus = PopupStatus.Show;
            BasePopupView.this.lifecycleRegistry.handleLifecycleEvent(Lifecycle.Event.ON_RESUME);
            BasePopupView.this.onShow();
            BasePopupView basePopupView = BasePopupView.this;
            if (basePopupView instanceof FullScreenPopupView) {
                basePopupView.focusAndProcessBackPress();
            }
            if (!(BasePopupView.this.popupInfo == null || BasePopupView.this.popupInfo.xPopupCallback == null)) {
                BasePopupView.this.popupInfo.xPopupCallback.onShow(BasePopupView.this);
            }
            if (BasePopupView.this.getHostWindow() != null && XPopupUtils.getDecorViewInvisibleHeight(BasePopupView.this.getHostWindow()) > 0 && !BasePopupView.this.hasMoveUp) {
                XPopupUtils.moveUpToKeyboard(XPopupUtils.getDecorViewInvisibleHeight(BasePopupView.this.getHostWindow()), BasePopupView.this);
            }
        }
    };
    protected Handler handler = new Handler(Looper.getMainLooper());
    private boolean hasModifySoftMode = false;
    private boolean hasMoveUp = false;
    private final Runnable initTask = new Runnable() {
        /* class com.youyi.yyviewsdklibrary.Dialog.core.BasePopupView.AnonymousClass2 */

        public void run() {
            if (BasePopupView.this.getHostWindow() != null) {
                if (BasePopupView.this.popupInfo.xPopupCallback != null) {
                    BasePopupView.this.popupInfo.xPopupCallback.beforeShow(BasePopupView.this);
                }
                BasePopupView.this.beforeShow();
                BasePopupView.this.lifecycleRegistry.handleLifecycleEvent(Lifecycle.Event.ON_START);
                BasePopupView basePopupView = BasePopupView.this;
                if (!(basePopupView instanceof FullScreenPopupView)) {
                    basePopupView.focusAndProcessBackPress();
                }
                BasePopupView basePopupView2 = BasePopupView.this;
                if (!(basePopupView2 instanceof AttachPopupView) && !(basePopupView2 instanceof BubbleAttachPopupView) && !(basePopupView2 instanceof PositionPopupView) && !(basePopupView2 instanceof PartShadowPopupView)) {
                    basePopupView2.initAnimator();
                    BasePopupView.this.doShowAnimation();
                    BasePopupView.this.doAfterShow();
                }
            }
        }
    };
    protected boolean isCreated = false;
    protected LifecycleRegistry lifecycleRegistry = new LifecycleRegistry(this);
    protected PopupAnimator popupContentAnimator;
    public PopupInfo popupInfo;
    public PopupStatus popupStatus = PopupStatus.Dismiss;
    private int preSoftMode = -1;
    protected ShadowBgAnimator shadowBgAnimator;
    private ShowSoftInputTask showSoftInputTask;
    private final int touchSlop;
    private float x;
    private float y;

    /* access modifiers changed from: protected */
    public void addOnUnhandledKeyListener(View view) {
    }

    /* access modifiers changed from: protected */
    public void applyDarkTheme() {
    }

    /* access modifiers changed from: protected */
    public void applyLightTheme() {
    }

    /* access modifiers changed from: protected */
    public void beforeDismiss() {
    }

    /* access modifiers changed from: protected */
    public void beforeShow() {
    }

    /* access modifiers changed from: protected */
    public int getImplLayoutId() {
        return -1;
    }

    /* access modifiers changed from: protected */
    public abstract int getInnerLayoutId();

    /* access modifiers changed from: protected */
    public List<String> getInternalFragmentNames() {
        return null;
    }

    /* access modifiers changed from: protected */
    public PopupAnimator getPopupAnimator() {
        return null;
    }

    /* access modifiers changed from: protected */
    public void initPopupContent() {
    }

    /* access modifiers changed from: protected */
    public boolean onBackPressed() {
        return false;
    }

    /* access modifiers changed from: protected */
    public void onCreate() {
    }

    /* access modifiers changed from: protected */
    public void onDismiss() {
    }

    /* access modifiers changed from: protected */
    public void onKeyboardHeightChange(int i) {
    }

    /* access modifiers changed from: protected */
    public void onShow() {
    }

    public BasePopupView(Context context) {
        super(context);
        this.touchSlop = ViewConfiguration.get(context).getScaledTouchSlop();
        setId(View.generateViewId());
        View inflate = LayoutInflater.from(context).inflate(getInnerLayoutId(), (ViewGroup) this, false);
        inflate.setAlpha(0.0f);
        addView(inflate);
    }

    @Override // android.arch.lifecycle.LifecycleOwner
    public Lifecycle getLifecycle() {
        return this.lifecycleRegistry;
    }

    public BasePopupView show() {
        FullScreenDialog fullScreenDialog;
        Activity context2Activity = XPopupUtils.context2Activity(this);
        if (!(context2Activity == null || context2Activity.isFinishing() || this.popupInfo == null || this.popupStatus == PopupStatus.Showing || this.popupStatus == PopupStatus.Dismissing)) {
            this.popupStatus = PopupStatus.Showing;
            if (this.popupInfo.isRequestFocus) {
                KeyboardUtils.hideSoftInput(context2Activity.getWindow());
            }
            if (!this.popupInfo.isViewMode && (fullScreenDialog = this.dialog) != null && fullScreenDialog.isShowing()) {
                return this;
            }
            getActivityContentView().post(this.attachTask);
        }
        return this;
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    /* JADX WARNING: Removed duplicated region for block: B:31:0x00a7  */
    /* Code decompiled incorrectly, please refer to instructions dump. */
    private void attachToHost() {
        /*
        // Method dump skipped, instructions count: 258
        */
        throw new UnsupportedOperationException("Method not decompiled: com.youyi.yyviewsdklibrary.Dialog.core.BasePopupView.attachToHost():void");
    }

    /* access modifiers changed from: protected */
    public View getWindowDecorView() {
        if (getHostWindow() == null) {
            return null;
        }
        return (ViewGroup) getHostWindow().getDecorView();
    }

    public View getActivityContentView() {
        return ((Activity) getContext()).getWindow().getDecorView().findViewById(16908290);
    }

    /* access modifiers changed from: protected */
    public int getActivityContentLeft() {
        if (!XPopupUtils.isLandscape(getContext())) {
            return 0;
        }
        int[] iArr = new int[2];
        ((Activity) getContext()).getWindow().getDecorView().findViewById(16908290).getLocationInWindow(iArr);
        return iArr[0];
    }

    /* access modifiers changed from: protected */
    public void init() {
        if (this.shadowBgAnimator == null) {
            this.shadowBgAnimator = new ShadowBgAnimator(this, getAnimationDuration(), getShadowBgColor());
        }
        if (this.popupInfo.hasBlurBg.booleanValue()) {
            BlurAnimator blurAnimator2 = new BlurAnimator(this, getShadowBgColor());
            this.blurAnimator = blurAnimator2;
            blurAnimator2.hasShadowBg = this.popupInfo.hasShadowBg.booleanValue();
            this.blurAnimator.decorBitmap = XPopupUtils.view2Bitmap(XPopupUtils.context2Activity(this).getWindow().getDecorView());
        }
        if ((this instanceof AttachPopupView) || (this instanceof BubbleAttachPopupView) || (this instanceof PartShadowPopupView) || (this instanceof PositionPopupView)) {
            initPopupContent();
        } else if (!this.isCreated) {
            initPopupContent();
        }
        if (!this.isCreated) {
            this.isCreated = true;
            onCreate();
            this.lifecycleRegistry.handleLifecycleEvent(Lifecycle.Event.ON_CREATE);
            if (this.popupInfo.xPopupCallback != null) {
                this.popupInfo.xPopupCallback.onCreated(this);
            }
        }
        this.handler.postDelayed(this.initTask, 10);
    }

    /* access modifiers changed from: protected */
    public void initAnimator() {
        BlurAnimator blurAnimator2;
        getPopupContentView().setAlpha(1.0f);
        if (this.popupInfo.customAnimator != null) {
            PopupAnimator popupAnimator = this.popupInfo.customAnimator;
            this.popupContentAnimator = popupAnimator;
            if (popupAnimator.targetView == null) {
                this.popupContentAnimator.targetView = getPopupContentView();
            }
        } else {
            PopupAnimator genAnimatorByPopupType = genAnimatorByPopupType();
            this.popupContentAnimator = genAnimatorByPopupType;
            if (genAnimatorByPopupType == null) {
                this.popupContentAnimator = getPopupAnimator();
            }
        }
        if (this.popupInfo.hasShadowBg.booleanValue()) {
            this.shadowBgAnimator.initAnimator();
        }
        if (this.popupInfo.hasBlurBg.booleanValue() && (blurAnimator2 = this.blurAnimator) != null) {
            blurAnimator2.initAnimator();
        }
        PopupAnimator popupAnimator2 = this.popupContentAnimator;
        if (popupAnimator2 != null) {
            popupAnimator2.initAnimator();
        }
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private void detachFromHost() {
        PopupInfo popupInfo2 = this.popupInfo;
        if (popupInfo2 == null || !popupInfo2.isViewMode) {
            FullScreenDialog fullScreenDialog = this.dialog;
            if (fullScreenDialog != null) {
                fullScreenDialog.dismiss();
                return;
            }
            return;
        }
        ViewGroup viewGroup = (ViewGroup) getParent();
        if (viewGroup != null) {
            viewGroup.removeView(this);
        }
    }

    public Window getHostWindow() {
        PopupInfo popupInfo2 = this.popupInfo;
        if (popupInfo2 != null && popupInfo2.isViewMode) {
            return ((Activity) getContext()).getWindow();
        }
        FullScreenDialog fullScreenDialog = this.dialog;
        if (fullScreenDialog == null) {
            return null;
        }
        return fullScreenDialog.getWindow();
    }

    /* access modifiers changed from: protected */
    public void doAfterShow() {
        this.handler.removeCallbacks(this.doAfterShowTask);
        this.handler.postDelayed(this.doAfterShowTask, (long) getAnimationDuration());
    }

    public void focusAndProcessBackPress() {
        PopupInfo popupInfo2 = this.popupInfo;
        if (popupInfo2 != null && popupInfo2.isRequestFocus) {
            setFocusableInTouchMode(true);
            setFocusable(true);
            if (Build.VERSION.SDK_INT >= 28) {
                addOnUnhandledKeyListener(this);
            } else {
                setOnKeyListener(new BackPressListener());
            }
            ArrayList arrayList = new ArrayList();
            XPopupUtils.findAllEditText(arrayList, (ViewGroup) getPopupContentView());
            if (arrayList.size() > 0) {
                this.preSoftMode = getHostWindow().getAttributes().softInputMode;
                if (this.popupInfo.isViewMode) {
                    getHostWindow().setSoftInputMode(16);
                    this.hasModifySoftMode = true;
                }
                for (int i = 0; i < arrayList.size(); i++) {
                    EditText editText = (EditText) arrayList.get(i);
                    if (Build.VERSION.SDK_INT >= 28) {
                        addOnUnhandledKeyListener(editText);
                    } else if (!XPopupUtils.hasSetKeyListener(editText)) {
                        editText.setOnKeyListener(new BackPressListener());
                    }
                    if (i == 0) {
                        if (this.popupInfo.autoFocusEditText) {
                            editText.setFocusable(true);
                            editText.setFocusableInTouchMode(true);
                            editText.requestFocus();
                            if (this.popupInfo.autoOpenSoftInput.booleanValue()) {
                                showSoftInput(editText);
                            }
                        } else if (this.popupInfo.autoOpenSoftInput.booleanValue()) {
                            showSoftInput(this);
                        }
                    }
                }
            } else if (this.popupInfo.autoOpenSoftInput.booleanValue()) {
                showSoftInput(this);
            }
        }
    }

    /* access modifiers changed from: protected */
    public void showSoftInput(View view) {
        if (this.popupInfo != null) {
            ShowSoftInputTask showSoftInputTask2 = this.showSoftInputTask;
            if (showSoftInputTask2 == null) {
                this.showSoftInputTask = new ShowSoftInputTask(view);
            } else {
                this.handler.removeCallbacks(showSoftInputTask2);
            }
            this.handler.postDelayed(this.showSoftInputTask, 10);
        }
    }

    public void dismissOrHideSoftInput() {
        if (KeyboardUtils.sDecorViewInvisibleHeightPre == 0) {
            dismiss();
        } else {
            KeyboardUtils.hideSoftInput(this);
        }
    }

    /* access modifiers changed from: package-private */
    public static class ShowSoftInputTask implements Runnable {
        View focusView;

        public ShowSoftInputTask(View view) {
            this.focusView = view;
        }

        public void run() {
            View view = this.focusView;
            if (view != null) {
                KeyboardUtils.showSoftInput(view);
            }
        }
    }

    /* access modifiers changed from: protected */
    public boolean processKeyEvent(int i, KeyEvent keyEvent) {
        if (i != 4 || keyEvent.getAction() != 1 || this.popupInfo == null) {
            return false;
        }
        if (!onBackPressed() && this.popupInfo.isDismissOnBackPressed.booleanValue() && (this.popupInfo.xPopupCallback == null || !this.popupInfo.xPopupCallback.onBackPressed(this))) {
            dismissOrHideSoftInput();
        }
        return true;
    }

    /* access modifiers changed from: package-private */
    public class BackPressListener implements OnKeyListener {
        BackPressListener() {
        }

        public boolean onKey(View view, int i, KeyEvent keyEvent) {
            return BasePopupView.this.processKeyEvent(i, keyEvent);
        }
    }


    /* access modifiers changed from: protected */
    public PopupAnimator genAnimatorByPopupType() {
        PopupInfo popupInfo2 = this.popupInfo;
        if (popupInfo2 == null || popupInfo2.popupAnimation == null) {
            return null;
        }
        switch (this.popupInfo.popupAnimation.ordinal()) {
            case 1:
            case 2:
            case 3:
            case 4:
            case 5:
                return new ScaleAlphaAnimator(getPopupContentView(), getAnimationDuration(), this.popupInfo.popupAnimation);
            case 6:
            case 7:
            case 8:
            case 9:
                return new TranslateAlphaAnimator(getPopupContentView(), getAnimationDuration(), this.popupInfo.popupAnimation);
            case 10:
            case 11:
            case 12:
            case 13:
                return new TranslateAnimator(getPopupContentView(), getAnimationDuration(), this.popupInfo.popupAnimation);
            case 14:
            case 15:
            case 16:
            case 17:
            case 18:
            case 19:
            case 20:
            case 21:
                return new ScrollScaleAnimator(getPopupContentView(), getAnimationDuration(), this.popupInfo.popupAnimation);
            case 22:
                return new EmptyAnimator(getPopupContentView(), getAnimationDuration());
            default:
                return null;
        }
    }

    /* access modifiers changed from: protected */
    public void doShowAnimation() {
        BlurAnimator blurAnimator2;
        ShadowBgAnimator shadowBgAnimator2;
        PopupInfo popupInfo2 = this.popupInfo;
        if (popupInfo2 != null) {
            if (popupInfo2.hasShadowBg.booleanValue() && !this.popupInfo.hasBlurBg.booleanValue() && (shadowBgAnimator2 = this.shadowBgAnimator) != null) {
                shadowBgAnimator2.animateShow();
            } else if (this.popupInfo.hasBlurBg.booleanValue() && (blurAnimator2 = this.blurAnimator) != null) {
                blurAnimator2.animateShow();
            }
            PopupAnimator popupAnimator = this.popupContentAnimator;
            if (popupAnimator != null) {
                popupAnimator.animateShow();
            }
        }
    }

    /* access modifiers changed from: protected */
    public void doDismissAnimation() {
        BlurAnimator blurAnimator2;
        ShadowBgAnimator shadowBgAnimator2;
        PopupInfo popupInfo2 = this.popupInfo;
        if (popupInfo2 != null) {
            if (popupInfo2.hasShadowBg.booleanValue() && !this.popupInfo.hasBlurBg.booleanValue() && (shadowBgAnimator2 = this.shadowBgAnimator) != null) {
                shadowBgAnimator2.animateDismiss();
            } else if (this.popupInfo.hasBlurBg.booleanValue() && (blurAnimator2 = this.blurAnimator) != null) {
                blurAnimator2.animateDismiss();
            }
            PopupAnimator popupAnimator = this.popupContentAnimator;
            if (popupAnimator != null) {
                popupAnimator.animateDismiss();
            }
        }
    }

    public View getPopupContentView() {
        return getChildAt(0);
    }

    public View getPopupImplView() {
        return ((ViewGroup) getPopupContentView()).getChildAt(0);
    }

    public int getAnimationDuration() {
        PopupInfo popupInfo2 = this.popupInfo;
        if (popupInfo2 == null) {
            return 0;
        }
        if (popupInfo2.popupAnimation == PopupAnimation.NoAnimation) {
            return 1;
        }
        return this.popupInfo.animationDuration >= 0 ? this.popupInfo.animationDuration : XPopup.getAnimationDuration() + 1;
    }

    public int getShadowBgColor() {
        PopupInfo popupInfo2 = this.popupInfo;
        return (popupInfo2 == null || popupInfo2.shadowBgColor == 0) ? XPopup.getShadowBgColor() : this.popupInfo.shadowBgColor;
    }

    public int getStatusBarBgColor() {
        PopupInfo popupInfo2 = this.popupInfo;
        return (popupInfo2 == null || popupInfo2.statusBarBgColor == 0) ? XPopup.getStatusBarBgColor() : this.popupInfo.statusBarBgColor;
    }

    /* access modifiers changed from: protected */
    public int getMaxWidth() {
        return this.popupInfo.maxWidth;
    }

    /* access modifiers changed from: protected */
    public int getMaxHeight() {
        return this.popupInfo.maxHeight;
    }

    /* access modifiers changed from: protected */
    public int getPopupWidth() {
        return this.popupInfo.popupWidth;
    }

    /* access modifiers changed from: protected */
    public int getPopupHeight() {
        return this.popupInfo.popupHeight;
    }

    public void dismiss() {
        this.handler.removeCallbacks(this.attachTask);
        this.handler.removeCallbacks(this.initTask);
        if (this.popupStatus != PopupStatus.Dismissing && this.popupStatus != PopupStatus.Dismiss) {
            this.popupStatus = PopupStatus.Dismissing;
            clearFocus();
            PopupInfo popupInfo2 = this.popupInfo;
            if (!(popupInfo2 == null || popupInfo2.xPopupCallback == null)) {
                this.popupInfo.xPopupCallback.beforeDismiss(this);
            }
            beforeDismiss();
            this.lifecycleRegistry.handleLifecycleEvent(Lifecycle.Event.ON_PAUSE);
            doDismissAnimation();
            doAfterDismiss();
        }
    }

    public void smartDismiss() {
        this.handler.post(new Runnable() {
            /* class com.youyi.yyviewsdklibrary.Dialog.core.BasePopupView.AnonymousClass4 */

            public void run() {
                BasePopupView basePopupView = BasePopupView.this;
                basePopupView.delayDismiss((long) (basePopupView.getAnimationDuration() + 50));
            }
        });
    }

    public void delayDismiss(long j) {
        if (j < 0) {
            j = 0;
        }
        this.handler.postDelayed(new Runnable() {
            /* class com.youyi.yyviewsdklibrary.Dialog.core.BasePopupView.AnonymousClass5 */

            public void run() {
                BasePopupView.this.dismiss();
            }
        }, j);
    }

    public void delayDismissWith(long j, Runnable runnable) {
        this.dismissWithRunnable = runnable;
        delayDismiss(j);
    }

    /* access modifiers changed from: protected */
    public void doAfterDismiss() {
        PopupInfo popupInfo2 = this.popupInfo;
        if (popupInfo2 != null && popupInfo2.autoOpenSoftInput.booleanValue() && !(this instanceof PartShadowPopupView)) {
            KeyboardUtils.hideSoftInput(this);
        }
        this.handler.removeCallbacks(this.doAfterDismissTask);
        this.handler.postDelayed(this.doAfterDismissTask, (long) getAnimationDuration());
    }

    public void dismissWith(Runnable runnable) {
        this.dismissWithRunnable = runnable;
        dismiss();
    }

    public boolean isShow() {
        return this.popupStatus == PopupStatus.Show;
    }

    public boolean isDismiss() {
        return this.popupStatus == PopupStatus.Dismiss;
    }

    public void toggle() {
        if (isShow()) {
            dismiss();
        } else {
            show();
        }
    }

    /* access modifiers changed from: protected */
    public void tryRemoveFragments() {
        if (getContext() instanceof FragmentActivity) {
            FragmentManager supportFragmentManager = ((FragmentActivity) getContext()).getSupportFragmentManager();
            List<Fragment> fragments = supportFragmentManager.getFragments();
            List<String> internalFragmentNames = getInternalFragmentNames();
            if (!(fragments == null || fragments.size() <= 0 || internalFragmentNames == null)) {
                for (int i = 0; i < fragments.size(); i++) {
                    if (internalFragmentNames.contains(fragments.get(i).getClass().getSimpleName())) {
                        supportFragmentManager.beginTransaction().remove(fragments.get(i)).commitAllowingStateLoss();
                    }
                }
            }
        }
    }

    @OnLifecycleEvent(Lifecycle.Event.ON_DESTROY)
    public void onDestroy() {
        onDetachedFromWindow();
        detachFromHost();
        destroy();
    }

    public void destroy() {
        this.lifecycleRegistry.handleLifecycleEvent(Lifecycle.Event.ON_DESTROY);
        PopupInfo popupInfo2 = this.popupInfo;
        if (popupInfo2 != null) {
            popupInfo2.atView = null;
            this.popupInfo.xPopupCallback = null;
            this.popupInfo.hostLifecycle = null;
            if (!(this.popupInfo.customAnimator == null || this.popupInfo.customAnimator.targetView == null)) {
                this.popupInfo.customAnimator.targetView.animate().cancel();
            }
            if (this.popupInfo.isViewMode) {
                tryRemoveFragments();
            }
            if (this.popupInfo.isDestroyOnDismiss) {
                this.popupInfo = null;
            }
        }
        FullScreenDialog fullScreenDialog = this.dialog;
        if (fullScreenDialog != null) {
            if (fullScreenDialog.isShowing()) {
                this.dialog.dismiss();
            }
            this.dialog.contentView = null;
            this.dialog = null;
        }
        ShadowBgAnimator shadowBgAnimator2 = this.shadowBgAnimator;
        if (!(shadowBgAnimator2 == null || shadowBgAnimator2.targetView == null)) {
            this.shadowBgAnimator.targetView.animate().cancel();
        }
        BlurAnimator blurAnimator2 = this.blurAnimator;
        if (blurAnimator2 != null && blurAnimator2.targetView != null) {
            this.blurAnimator.targetView.animate().cancel();
            if (this.blurAnimator.decorBitmap != null && !this.blurAnimator.decorBitmap.isRecycled()) {
                this.blurAnimator.decorBitmap.recycle();
                this.blurAnimator.decorBitmap = null;
            }
        }
    }

    /* access modifiers changed from: protected */
    public void onDetachedFromWindow() {
        super.onDetachedFromWindow();
        this.handler.removeCallbacksAndMessages(null);
        if (this.popupInfo != null) {
            if (getWindowDecorView() != null) {
                KeyboardUtils.removeLayoutChangeListener(getHostWindow(), this);
            }
            if (this.popupInfo.isViewMode && this.hasModifySoftMode) {
                getHostWindow().setSoftInputMode(this.preSoftMode);
                this.hasModifySoftMode = false;
            }
            if (this.popupInfo.isDestroyOnDismiss) {
                destroy();
            }
        }
        PopupInfo popupInfo2 = this.popupInfo;
        if (popupInfo2 != null && popupInfo2.hostLifecycle != null) {
            this.popupInfo.hostLifecycle.removeObserver(this);
        } else if (getContext() != null && (getContext() instanceof FragmentActivity)) {
            ((FragmentActivity) getContext()).getLifecycle().removeObserver(this);
        }
        this.popupStatus = PopupStatus.Dismiss;
        this.showSoftInputTask = null;
        this.hasMoveUp = false;
    }

    private void passTouchThrough(MotionEvent motionEvent) {
        PopupInfo popupInfo2 = this.popupInfo;
        if (popupInfo2 == null) {
            return;
        }
        if (!(popupInfo2.isClickThrough || this.popupInfo.isTouchThrough)) {
            return;
        }
        if (this.popupInfo.isViewMode) {
            ViewGroup viewGroup = (ViewGroup) ((Activity) getContext()).getWindow().getDecorView();
            for (int i = 0; i < viewGroup.getChildCount(); i++) {
                View childAt = viewGroup.getChildAt(i);
                if (!(childAt instanceof BasePopupView)) {
                    childAt.dispatchTouchEvent(motionEvent);
                }
            }
            return;
        }
        ((Activity) getContext()).dispatchTouchEvent(motionEvent);
    }

    /* JADX WARNING: Code restructure failed: missing block: B:8:0x0027, code lost:
        if (r0 != 3) goto L_0x00d4;
     */
    /* Code decompiled incorrectly, please refer to instructions dump. */
    public boolean onTouchEvent(MotionEvent r10) {
        /*
        // Method dump skipped, instructions count: 213
        */
        throw new UnsupportedOperationException("Method not decompiled: com.youyi.yyviewsdklibrary.Dialog.core.BasePopupView.onTouchEvent(android.view.MotionEvent):boolean");
    }
}
